from rest_framework import serializers
from apps.users.models import User


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id','username','mobile','email','password']
        extra_kwargs = {
            'password': {
                'write_only': True,
                'max_length':15,
                'min_length':6
            }
        }

    def create(self,validated_data):
        return User.objects.create_user(**validated_data)

        # user = User.objects.create(**validated_data)
        # user.set_password(validated_data.get('password'))
        # user.save()
        # return user